package ventanas;
/*
import beans.Caja;
import beans.Documentos;
import interfaces.Buscadores;
import java.awt.Frame;
import java.util.Date;
import javax.swing.JOptionPane;
import managers.ManejadorConfiguraciones;
import managers.ManejadorDocumentos;

public class Formulario_Cuadre_Caja extends javax.swing.JDialog {

    /** Creates new form Formulario_Cuadre_Caja
    ManejadorDocumentos md;
    ManejadorConfiguraciones mc;
    Buscadores bu;
    Frame parent;
    int funcion = 0;
    Documentos d;
    int op = 0;
    Caja c;

    public Formulario_Cuadre_Caja(java.awt.Frame parent, boolean modal, ManejadorDocumentos md, Buscadores bu, int funcion, Caja c) {
        super(parent, modal);
        this.c = c;
        this.md = md;
        this.bu = bu;
        mc = new ManejadorConfiguraciones(md.getModel());
        this.parent = parent;
        this.funcion = funcion;


        initComponents();

        valoractual.setText(utilidades.FormatoNumeros.formatear(c.getSaldoactual() + ""));
        valoractual2.setText(utilidades.FormatoNumeros.formatear(c.getSaldoactual() + ""));

        utilidades.FormatoNumeros fn = new utilidades.FormatoNumeros(valoractual);
        valoractual.addKeyListener(fn);
        valoractual.addFocusListener(fn);

        fn = new utilidades.FormatoNumeros(valoractual2);
        valoractual2.addKeyListener(fn);
        valoractual2.addFocusListener(fn);

        fn = new utilidades.FormatoNumeros(valorretiro);
        valorretiro.addKeyListener(fn);
        valorretiro.addFocusListener(fn);

        fn = new utilidades.FormatoNumeros(valorsobrante);
        valorsobrante.addKeyListener(fn);
        valorsobrante.addFocusListener(fn);

        fn = new utilidades.FormatoNumeros(cajacuadrada);
        cajacuadrada.addKeyListener(fn);
        cajacuadrada.addFocusListener(fn);

        fn = new utilidades.FormatoNumeros(saldosiguiente);
        saldosiguiente.addKeyListener(fn);
        saldosiguiente.addFocusListener(fn);

        if (funcion == 0) {
            tab.remove(1);
        } else {
            tab.remove(0);
        }

        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    public static int cuadrarCaja(java.awt.Frame parent, boolean modal, ManejadorDocumentos md, Buscadores bu, int funcion, Caja c) {
        Formulario_Cuadre_Caja fcc = new Formulario_Cuadre_Caja(parent, modal, md, bu, funcion, c);
        return fcc.op;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        tab = new javax.swing.JTabbedPane();
        panel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        valorfaltante = new javax.swing.JTextField();
        valorsobrante = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cajacuadrada = new javax.swing.JTextField();
        valoractual = new javax.swing.JTextField();
        panel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        valoractual2 = new javax.swing.JTextField();
        valorretiro = new javax.swing.JTextField();
        saldosiguiente = new javax.swing.JTextField();
        guardar = new javax.swing.JButton();
        salir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(212, 233, 255));
        jPanel1.setLayout(null);

        tab.setTabPlacement(javax.swing.JTabbedPane.RIGHT);

        panel1.setBackground(new java.awt.Color(212, 233, 255));

        jLabel1.setText("Valor Actual en Caja  $");

        jLabel2.setText("Valor Faltante            $");

        jLabel3.setText("Caja Cuadrada          $");

        valorfaltante.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        valorfaltante.setText("0.00");
        valorfaltante.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                valorfaltanteKeyReleased(evt);
            }
        });

        valorsobrante.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        valorsobrante.setText("0.00");
        valorsobrante.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                valorsobranteKeyReleased(evt);
            }
        });

        jLabel8.setText("Valor Sobrante          $");

        cajacuadrada.setEditable(false);
        cajacuadrada.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        cajacuadrada.setText("0.00");

        valoractual.setEditable(false);
        valoractual.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        valoractual.setText("0.00");

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cajacuadrada, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                    .addComponent(valorsobrante, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                    .addComponent(valorfaltante, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                    .addComponent(valoractual, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))
                .addGap(93, 93, 93))
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(valoractual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(valorfaltante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(valorsobrante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cajacuadrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        tab.addTab("tab1", panel1);

        panel2.setBackground(new java.awt.Color(212, 233, 255));

        jLabel5.setText("Valor Actual en Caja                  $");

        jLabel6.setText("Valor para iniciar Caja                $");

        jLabel7.setText("Valor en Caja Principal               $");

        valoractual2.setEditable(false);
        valoractual2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        valoractual2.setText("0.00");

        valorretiro.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        valorretiro.setText("0.00");
        valorretiro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                valorretiroKeyReleased(evt);
            }
        });

        saldosiguiente.setEditable(false);
        saldosiguiente.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        saldosiguiente.setText("0.00");

        javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
        panel2.setLayout(panel2Layout);
        panel2Layout.setHorizontalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(12, 12, 12)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(valoractual2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(saldosiguiente, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(valorretiro, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)))
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(63, 63, 63))
        );
        panel2Layout.setVerticalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addComponent(valoractual2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(valorretiro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saldosiguiente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)
                        .addGap(13, 13, 13)
                        .addComponent(jLabel7)))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        tab.addTab("tab1", panel2);

        jPanel1.add(tab);
        tab.setBounds(0, 0, 450, 150);

        guardar.setBackground(new java.awt.Color(0, 153, 255));
        guardar.setFont(new java.awt.Font("Tahoma", 1, 11));
        guardar.setForeground(new java.awt.Color(0, 51, 153));
        guardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ok.png"))); // NOI18N
        guardar.setText("Guardar");
        guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarActionPerformed(evt);
            }
        });
        jPanel1.add(guardar);
        guardar.setBounds(110, 160, 93, 23);

        salir.setBackground(new java.awt.Color(0, 153, 255));
        salir.setFont(new java.awt.Font("Tahoma", 1, 11));
        salir.setForeground(new java.awt.Color(0, 51, 153));
        salir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/bulletCritical.png"))); // NOI18N
        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirActionPerformed(evt);
            }
        });
        jPanel1.add(salir);
        salir.setBounds(210, 160, 100, 23);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarActionPerformed
        // TODO add your handling code here:
        //  guardar();
        c.setHoracierre(new Date());
        if (funcion == 0) {
            c.setEstado(1);
            md.modificar(c);
            //   parent.dispose();
            JOptionPane.showMessageDialog(null, "Caja Cerrada con Exito");
        } else {
            if (!valorretiro.getText().trim().equals("")) {
                double ret = Double.parseDouble(valorretiro.getText().replaceAll(",", ""));
                if (ret > 0) {
                    c.setCajaprincipal(c.getCajaprincipal() + c.getSaldoactual() - ret);
                    c.setSaldoactual(ret);
                }
            }
            c.setEstado(1);
            double saldo = c.getSaldoactual();
            double cajaprincipal = c.getCajaprincipal();
            md.modificar(c);
            c = new Caja();
            c.setSaldoactual(saldo);
            c.setCajaprincipal(cajaprincipal);
            md.crear(c);
            
            JOptionPane.showMessageDialog(null, "Caja Cerrada con Exito");
            JOptionPane.showMessageDialog(null, "Se ha inciado un nuevo corte");
            op = 1;
        }
}//GEN-LAST:event_guardarActionPerformed

    private void salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirActionPerformed
        // TODO add your handling code here:
        op = 0;
        this.dispose();
}//GEN-LAST:event_salirActionPerformed

    private void valorretiroKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valorretiroKeyReleased
        // TODO add your handling code here:
        if (!valorretiro.getText().trim().equals("")) {
            double t = c.getSaldoactual();
            double dev = Double.parseDouble(valorretiro.getText().replaceAll(",", ""));
            dev = t - dev;
            if (dev >= 0) {
                saldosiguiente.setText(utilidades.FormatoNumeros.formatear(dev + ""));
            }
        }
    }//GEN-LAST:event_valorretiroKeyReleased

    private void valorfaltanteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valorfaltanteKeyReleased
        // TODO add your handling code here:
        if (!valorfaltante.getText().trim().equals("")) {
            valorsobrante.setText("0.00");
            double t = c.getSaldoactual();
            double dev = Double.parseDouble(valorfaltante.getText().replaceAll(",", ""));
            dev = t - dev;
            if (dev >= 0) {
                cajacuadrada.setText(utilidades.FormatoNumeros.formatear(dev + ""));
            }
        }
    }//GEN-LAST:event_valorfaltanteKeyReleased

    private void valorsobranteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valorsobranteKeyReleased
        // TODO add your handling code here:
        if (!valorsobrante.getText().trim().equals("")) {
            valorfaltante.setText("0.00");
            double t = c.getSaldoactual();
            double dev = Double.parseDouble(valorsobrante.getText().replaceAll(",", ""));
            dev = t + dev;
            if (dev >= 0) {
                cajacuadrada.setText(utilidades.FormatoNumeros.formatear(dev + ""));
            }
        }
    }//GEN-LAST:event_valorsobranteKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cajacuadrada;
    private javax.swing.JButton guardar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel panel1;
    private javax.swing.JPanel panel2;
    private javax.swing.JTextField saldosiguiente;
    private javax.swing.JButton salir;
    private javax.swing.JTabbedPane tab;
    private javax.swing.JTextField valoractual;
    private javax.swing.JTextField valoractual2;
    private javax.swing.JTextField valorfaltante;
    private javax.swing.JTextField valorretiro;
    private javax.swing.JTextField valorsobrante;
    // End of variables declaration//GEN-END:variables
}
*/